#include"sqlite.hpp"

#include<iostream>
#include<cassert>
#include"sqlite.hpp"

#include<iostream>
#include<cassert>
#include<vector>
#include<string>
int select_stu_callback(void* arg,int col_count,char** result,char** fields_name) 
{
    std::vector<std::string> *nameptr=static_cast<std::vector<std::string>*>(arg);
    nameptr->push_back(result[0]);
    return 0;
}

int main()
{
    SqliteHelper sqlhelp("./test.db");
    //打开文件
    assert(sqlhelp.Open());
    //创建表
    const char*ct="create table if not exists student(id int primary key,name varchar(20),age int);";
    assert(sqlhelp.Exec(ct,nullptr,nullptr));

    //const char*insert="insert into student values(12345678,'张三',18),(12345679,'李四',20);";
    const char*insert="insert or ignore into student  values(1, '小明', 18), (2, '小黑', 19), (3, '小红', 18);";
    assert(sqlhelp.Exec(insert,nullptr,nullptr));


    std::vector<std::string> names;
    const char* select_name="select name from student;";
    assert(sqlhelp.Exec(select_name,select_stu_callback,&names));
    for(auto &str:names)
    {
        std::cout<<str<<" ";
    }


    return 0;
}
